package com.zzptc.fxh.myapplication.adapter;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.TextView;

import androidx.annotation.NonNull;
import androidx.recyclerview.widget.RecyclerView;

import com.zzptc.fxh.myapplication.MainActivity;
import com.zzptc.fxh.myapplication.R;

import java.util.List;

public class MyAdapter extends RecyclerView.Adapter<MyAdapter.ViewHoder>{
    private Context context;
    private List<String> list;
    public MyAdapter(Context context,List<String> list){
        //给采用属性赋值
        this.context=context;
        this.list=list;
    }

    @NonNull
    @Override
    public MyAdapter.ViewHoder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {
        //View v=View.inflate(MainActivity.this,R.layout.rv_item,null);
        View v= LayoutInflater.from(context).inflate(R.layout.rv_item,parent,false);
        return new ViewHoder(v);
    }

    @Override
    public void onBindViewHolder(@NonNull ViewHoder holder, int position) {
        String s = list.get(position);
        holder.textView.setText(s);

    }

    @Override
    public int getItemCount() {
        return list.size();
    }

    public class ViewHoder extends RecyclerView.ViewHolder {
        private ImageView imageView;
        private TextView textView;
        public ViewHoder(@NonNull View itemView) {
            super(itemView);
            imageView=itemView.findViewById(R.id.iv_pic);
            textView=itemView.findViewById(R.id.tv_info);
        }
    }
}
